<?php
/**
 * Created by PhpStorm.
 * User: sunzexin
 * Date: 2018/3/15
 * Time: 11:14
 */

namespace App\Http\Logics\MiniProgramAdmin;


use App\ProductContent;
use App\Http\Logics\CommonLogic;
use App\Http\Logics\BaseLogic;
class ProductContentLogic extends BaseLogic
{
    public static function updatePartyContent($data)
    {
        errorLog($data);
        // 将之前的删除
        ProductContent::where('product_id' ,$data['product_id'])->delete();

        $content = json_decode($data['content_str']);
        foreach ($content as $key => $item){
            $product_content = new ProductContent();
            // 公众参数
            $product_content->product_id = $data['product_id'];
            $product_content->sort = $key;
            $response = CommonLogic::handleContent($product_content, $item);
            if ($response->code){
                return self::response($response->code, $response->data);
            }
        }
        return self::response(self::SUCCESS);
    }
}